﻿<%@ page language="java" import="com.newcrm.config.Const,com.newcrm.util.Util,com.newcrm.db.DealFieldManager,com.newcrm.bean.*,java.util.List,java.util.Map" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
  Map<String, Object> dealInfo = (Map<String, Object>)request.getAttribute("dealInfo");
  List<ExtInfo> extInfos = (List<ExtInfo>)request.getAttribute("extInfos");
  List<Map<String, Object>> fields = (List<Map<String, Object>>) request.getAttribute("fields");

  List<Map<String, Object>> customerInfos = (List<Map<String, Object>>)request.getAttribute("customerInfo");
  User user = (User) session.getAttribute("user");
  Map<Integer, CompanyInfo> companys = (Map<Integer, CompanyInfo>) application.getAttribute(Const.APPLICATION_COMPANYS);
  CompanyInfo companyInfo = companys.get(Integer.valueOf(user.companyId));
  List<Map<String, Object>> dealCategory = companyInfo.dealCategorys;
  List<User> users = companyInfo.users;
  String responsibleUserId = (String) dealInfo.get("ResponsibleUserId");
  // 由于不是上级部门管理员，没有查看的权限，所以只要能打开页面的非本人用户，都有审批权
  boolean isUserSelf = user.userId.equals(responsibleUserId);
  int dealStatus = ((Integer)dealInfo.get("DealStatus")).intValue();
  String dealName = (String) dealInfo.get("Name");
  int dealId = ((Integer)dealInfo.get("DealId")).intValue();
  String note = (String) dealInfo.get("Note");
  if (note == null) {
    note = "";
  }
  String shortNote = "";
  if (note.length() <= Const.DEAL_NOTE_SHORTLENGTH) {
    shortNote = note;
  } else {
    shortNote = note.substring(0, Const.DEAL_NOTE_SHORTLENGTH);
  }
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title><%=Util.HTMLEncode(dealName)%></title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="renderer" content="webkit"/>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <link rel="shortcut icon" href="<%=request.getContextPath()%>/images/qikebao.ico" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/all.css?ver=<%=Const.VERSION%>">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/datepicker.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap-datetimepicker.min.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/uploadify.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/magnific-popup.css">
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-1.11.1.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-ui.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.bootstrap-growl.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/moment.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap-datepicker.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap-datetimepicker.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/daterangepicker.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.magnific-popup.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.cookie.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.uploadify.v3.2.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/popbox.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/dealNote.js?ver=<%=Const.VERSION%>"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/dealDetail.js?ver=<%=Const.VERSION%>"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/common.js?ver=<%=Const.VERSION%>"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/rightTask.js?ver=<%=Const.VERSION%>"></script>
  <script language="JavaScript">
    var isUserSelf = '<%=isUserSelf%>';
    var allUsers = new Array();
    <%if (users != null) {
        for (User u:users) { %>
    allUsers.push({id:"<%=u.userId%>",name:"<%=Util.UEncode(u.name)%>",photo:"<%=u.imgPath%>"});
    <%  }
      } %>
    var allDealsCategory = new Array();
    <%if (dealCategory != null) {
        for (Map<String, Object> category:dealCategory) {
          String color = (String) category.get("Color");
          if (color == null || color.trim().length() == 0) {
            color = "000000";
          }
        %>
    allDealsCategory.push({id:"<%=category.get("DealCategoryId")%>",name:"<%=Util.UEncode((String)category.get("DealCategoryName"))%>", color:"<%=color%>"});
    <%  }
      } %>
    var loginUserId = '<%=user.userId%>';
    var isAdmin = <%=user.isAdmin%>;
    var customerId = "<%=dealInfo.get("CustomerId")%>";
    var _dealStatus = <%=dealStatus%>;
  </script>
</head>
<body class="customerdetail">
  <jsp:include page="topNavi.jsp" flush="true"/>
  <div class="main-page">
    <div class="title top20">
    <table>
    <tr>
      <td class="avatar"><img src="<%=request.getContextPath()%>/images/avatar_deal.png"></td>
      <td>
        <div class="right">
          <a href="<%=request.getContextPath()%>/deals/<%=dealId%>/edit" id="updatedeal-button" title="修改销售机会" class="iconbutton" href="#"><i class="fa fa-pencil"></i></a>
          <% if (user.isCanDelete()) {%>
            <a title="删除销售机会" class="iconbutton" href="#" id="deletedeal-button"><i class="fa fa-trash-o"></i></a>
         <%}%>
          <div class="deal_buttons" id="status_links">
            <% //访问的人如果是admin，不需要审批
              if (user.isAdmin()) {
            %>
            <a class="pending" href="#" v="1" id="pending_link"><i class="fa fa-circle-o-notch"></i> 跟踪</a>
            <a class="won" href="#" v="2" id="won_link"><i class="fa fa-thumbs-up"></i> 成功</a>
            <a class="lost" href="#" v="3" id="lost_link"><i class="fa fa-thumbs-o-down"></i> 失败</a>

            <% //访问的人如果是本人，显示正常页面(groupAdmin 需要admin审批)
              } else if (responsibleUserId.equals(user.userId)) {
            %>
            <a class="pending" href="#" v="1" id="pending_link"><i class="fa fa-circle-o-notch"></i> 跟踪</a>
            <a class="confirm" href="#" v="4" id="confirm_link"><i class="fa fa-thumbs-o-up"></i> 审核</a>
            <a class="lost" href="#" v="3" id="lost_link"><i class="fa fa-thumbs-o-down"></i> 失败</a>
            <% //访问的人如果不是本人，那就应该是admin或者部门主管，否则访问不了，仅显示审批界面
              } else {
            %>
            <a class="won" href="#" v="2" id="won_link"><i class="fa fa-thumbs-up"></i> 成功</a>
            <a class="pending" href="#" v="1" id="pending_link"><i class="fa fa-circle-o-notch"></i> 跟踪</a>
            <% } %>
          </div>
        </div>
        <h1><span id="categoryName" cate="<%=dealInfo.get("CategoryId")%>" title="销售机会分类" class="category"></span><a class="customer" target="_blank" href="<%=request.getContextPath()%>/<%=Util.HTMLEncode(Util.getCustomerUrlById((Integer)dealInfo.get("CustomerId"), customerInfos))%>"><%=Util.HTMLEncode(Util.getCustomerNameById((Integer)dealInfo.get("CustomerId"), customerInfos))%></a>：<%=Util.HTMLEncode(dealName)%></h1>
        <div class="dealdetail">
          <div title="创建时间"><i class="fa fa-calendar-o fa-fw"></i> <%=dealInfo.get("CreateDate")%></div>
          <% if (Util.str2Int(dealInfo.get("Price")) > 0) {%>
          <div title="金额"><i class="fa fa-yen fa-fw"></i> <%=dealInfo.get("Price")%> 元
          <%if (Util.str2Int(dealInfo.get("Commission")) > 0) {%>
            <span class="split">/</span><%=dealInfo.get("Commission")%> 元提成
          <% }%>
          </div>
          <%}%>
          <div title="负责人"><i class="fa fa-user fa-fw"></i> <%=Util.getUserNameById(responsibleUserId, users)%></div>
        </div>
      </td>
    </tr>
    </table>
    </div>
    <div class="body">
      <table>
        <tr>
          <td class="content">
            <div>
              <div class="inputarea">
                <textarea cols="40" data-focus-priority="1" id="reMark" rows="16" style="width:99%;height:60px"></textarea>
                <div class="bottom">
                  <span>
                    <a title="添加文件" class="iconbutton" href="file"><i class="fa fa-paperclip"></i></a>
                    <div class="desc file" id="desc_file">
                      <div class="icon"><div class="iconbg"></div></div>
                      <div><input type="file" id="file_upload" name="file_upload" /></div>
                    </div>
                  </span>
                  <span class="right"><a href="#" id="addnote-link" class="button green"><i class="fa fa-check"></i> 添加备注</a></span>
                </div>
              </div>
              <div class="clearfix"></div>
              <div id="notes_loading" class="loading">
                <div class="liner">
                  <h3>备注信息加载中...</h3>
                  <img alt="Dots-white" src="<%=request.getContextPath()%>/images/dots-white.gif" />
                </div>
              </div>
              <div class="feed_time_line_container">
                <div class="export_note"><a href="#" id="export_note_link"><i class="fa fa-fw fa-download"></i> 导出备注</a></div>
                <div class="feed_time_line" id="noteslist"></div>
              </div>
            </div>
          </td>
          <td class="rightdesc">
            <div class="container">
              <h1>任务</h1>
              <div class="tasklist overdue" id="overdueTasks">
                <h6> 已过期 </h6>
                <ul class="tasks"></ul>
              </div>
              <div class="tasklist" id="todayTasks">
                <h6> 今天 </h6>
                <ul class="tasks"></ul>
              </div>
              <div class="tasklist" id="tomorrowTasks">
                <h6> 明天 </h6>
                <ul class="tasks"></ul>
              </div>
              <div class="tasklist" id="thisWeekTasks">
                <h6> 本周 </h6>
                <ul class="tasks"></ul>
              </div>
              <div class="tasklist" id="nextWeekTasks">
                <h6> 下周 </h6>
                <ul class="tasks"></ul>
              </div>
              <div class="tasklist" id="laterTasks">
                <h6> 以后 </h6>
                <ul class="tasks"></ul>
              </div>
              <h1>详细信息</h1>
              <div class="data_group">
                <%for (ExtInfo extInfo:extInfos) {%>
                <div class="label"><%=DealFieldManager.getFieldName(extInfo.type, fields)%></div>
                <div class="value item"><%=Util.HTMLEncode(extInfo.info1)%></div>
                <%}%>
              </div>
              <%if (note != null && note.length() > 0) {%>
              <div class="data_group">
                <div class="label">简介</div>
                <div class="value short"><p><%=Util.HTMLEncode(shortNote)%>
                <%if (note.length() > shortNote.length()) {%>
                  <a href="#" id="deal_note_readMore_link">详细</a>
                <%}%>
                </p></div>
                <div class="value long" style="display: none"><p><%=Util.HTMLEncode(note)%></p></div>
              </div>
              <%}%>
            </div>
          </td>
        </tr>
      </table>
    </div>
  </div>

  <div id="deletenote-popup" class="white-popup mfp-hide">
    <div class="popup-title"><span class="title">删除备注信息</span> <span class="popup-close-button"><i class="fa fa-times"></i>&nbsp;</span></div>
    <div class="popup-content">
      确认要删除该备注信息吗？
    </div>
    <div class="buttonbar">
      <div class="right">
        <a id="deletenote-link" class="button blue small" href="#"><i class="fa fa-check"></i> 确定</a>
        <a class="button grey small popup-close-button" href="#"><i class="fa fa-times"></i> 取消</a>
      </div>
      <div class="message"></div>
    </div>
  </div>

  <div id="deletedeal-popup" class="white-popup mfp-hide">
    <div class="popup-title"><span class="title">删除销售机会</span> <span class="popup-close-button"><i class="fa fa-times"></i>&nbsp;</span></div>
    <div class="popup-content">
      确认要删除该销售机会吗？<br/>删除后，所有备注，任务和文件都将被删除。并且不可恢复。
    </div>
    <div class="buttonbar">
      <div class="right">
        <a id="deletedeal-link" class="button blue small" href="#"><i class="fa fa-check"></i> 确定</a>
        <a class="button grey small popup-close-button" href="#"><i class="fa fa-times"></i> 取消</a>
      </div>
      <div class="message"></div>
    </div>
  </div>

  <input type="hidden" id="referenceUrl" value="/deals/<%=dealId%>">
  <input type="hidden" id="referenceTitle" value="<%=Util.HTMLEncode(dealName)%>">
  <input type="hidden" id="referenceId" value="<%=dealId%>">
  <input type="hidden" id="referenceType" value="<%=Const.TYPE_DEAL%>">
  <input type="hidden" id="contextPath" value="<%=request.getContextPath()%>">

  <div class="movebox" id="updateTask">
    <div class='arrow'></div><div class='arrow-border'></div>
    <form class="task">
      <h3>修改任务</h3>
      <p class="task_body">
        <input id="update_taskId" type="hidden" value="" />
        <input class="autofocus" id="update_taskTitle" size="25" type="text" />
      </p>
      <div>
        <h5>到期时间</h5>
        <p>
          <div class="datetimepicker_container"><input class="autofocus dueDate" id="update_dueDate" size="25" type="text" /></div>
        </p>
        <h5>任务负责人</h5>
        <p>
          <select id="update_responsibleUserId" class="responsibleUserId"></select></p>
        <h5>任务分类</h5>
        <p>
          <select id="update_categoryId" class="categoryId"></select>
          <% if (user.isAdmin) {%>
          <a href="<%=request.getContextPath()%>/taskcategory" class="edit_categories">编辑分类</a>
          <% }%>
        </p>
        <p>
          <input class="checkbox" id="update_taskVisible" type="checkbox" value="1" />
          <label for="update_taskVisible">所有人可以看见这个任务</label>
        </p>
      </div>
      <div class="submit">
        <a id="update_task_button" class="button blue small closePopbox" href="#"><i class="fa fa-check"></i> 修改任务</a>
        &nbsp;&nbsp;<a href="#" class="closePopbox" id="update_task_cancel_link">取消</a>
      </div>
    </form>
  </div>
</body>
</html>